﻿namespace HRM.Update
{
    using DevExpress.LookAndFeel;
    using DevExpress.XtraEditors;
    using DevExpress.XtraWizard;
    using HRM.Update.Process;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class XfmUpdateOnline : XtraForm
    {
        private CompletionWizardPage completionWizardPage_0;
        private DefaultLookAndFeel defaultLookAndFeel_0;
        private DownloaderState downloaderState_0;
        private IContainer icontainer_0 = null;
        private const int int_0 = 0x400;
        private int int_1;
        private LabelControl labelControl_0;
        private LabelControl labelControl_1;
        private LabelControl labelControl_2;
        private LabelControl labelControl_3;
        private LabelControl labelControl_4;
        private LabelControl labelControl_5;
        private LabelControl labelControl_6;
        private LabelControl labelControl_7;
        private LabelControl labelControl_8;
        private LabelControl labelControl_9;
        private readonly ProcessDownLoad processDownLoad_0 = new ProcessDownLoad();
        private readonly ProcessInitUpdate processInitUpdate_0;
        private ProgressBarControl progressBarControl_0;
        private UpdateFile updateFile_0;
        private WelcomeWizardPage welcomeWizardPage_0;
        private WizardControl wizardControl_0;

        public event EnableButtonEventHander EnableButton;

        public XfmUpdateOnline()
        {
            this.method_8();
            this.labelControl_2.Text = Class0.smethod_0();
            this.processInitUpdate_0 = new ProcessInitUpdate();
            this.processInitUpdate_0.StatusString += new ProcessInitUpdate.StatusStringEventHander(this.method_3);
            this.processInitUpdate_0.StatusButton += new ProcessInitUpdate.StatusButtonEventHander(this.method_2);
            this.processInitUpdate_0.SendObject += new ProcessInitUpdate.SendObjectEventHander(this.method_1);
            this.processInitUpdate_0.Start();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.icontainer_0 != null))
            {
                this.icontainer_0.Dispose();
            }
            base.Dispose(disposing);
        }

        private void method_0(bool bool_0)
        {
            EnableButtonEventHander hander = this.EnableButton;
            if (hander != null)
            {
                hander(bool_0);
            }
        }

        private void method_1(object object_0)
        {
            this.updateFile_0 = (UpdateFile) object_0;
        }

        private void method_2(bool bool_0)
        {
            if (!base.InvokeRequired)
            {
                this.welcomeWizardPage_0.AllowNext = bool_0;
            }
            else
            {
                base.BeginInvoke(new ProcessInitUpdate.StatusButtonEventHander(this.method_2), new object[] { bool_0 });
            }
        }

        private void method_3(string string_0)
        {
            if (this.labelControl_1.InvokeRequired)
            {
                ProcessInitUpdate.StatusStringEventHander method = new ProcessInitUpdate.StatusStringEventHander(this.method_3);
                base.Invoke(method, new object[] { string_0 });
            }
            else
            {
                this.labelControl_1.Text = string_0;
            }
        }

        private void method_4(string string_0)
        {
            if (this.progressBarControl_0.InvokeRequired)
            {
                ProcessDownLoad.ExtractFileEventHander method = new ProcessDownLoad.ExtractFileEventHander(this.method_4);
                base.Invoke(method, new object[] { string_0 });
            }
            else
            {
                this.labelControl_5.Text = string_0;
            }
        }

        private void method_5(DownloaderState downloaderState_1)
        {
            if (this.labelControl_6.InvokeRequired)
            {
                ProcessDownLoad.DownLoadStatusEventHander method = new ProcessDownLoad.DownLoadStatusEventHander(this.method_5);
                base.Invoke(method, new object[] { downloaderState_1 });
            }
            else
            {
                switch (downloaderState_1)
                {
                    case DownloaderState.Preparing:
                        this.labelControl_6.Text = "... Đang chuẩn bị tải bản cập nhật";
                        break;

                    case DownloaderState.Prepared:
                        this.labelControl_6.Text = ".... Đ\x00e3 chuẩn bị";
                        break;

                    case DownloaderState.Working:
                        this.labelControl_6.Text = "... Đang tải bản cập nhật";
                        break;

                    case DownloaderState.Ended:
                        this.labelControl_6.Text = ". Đ\x00e3 tải xong";
                        break;

                    case DownloaderState.EndedWithError:
                        this.labelControl_6.Text = "Đường dẫn kh\x00f4ng hợp lệ, hoặc kh\x00f4ng t\x00ecm thấy bản cập nhật";
                        this.completionWizardPage_0.AllowCancel = true;
                        break;

                    case DownloaderState.PrepareExtract:
                        this.labelControl_5.Text = "...Bắt đầu cập nhật";
                        break;

                    case DownloaderState.EndExtract:
                        this.downloaderState_0 = downloaderState_1;
                        this.labelControl_5.Text = ". Đ\x00e3 cập nhật xong";
                        this.labelControl_4.Text = "Nhấn n\x00fat <Ho\x00e0n Tất> để ho\x00e0n th\x00e0nh tiến tr\x00ecnh cập nhật.";
                        break;
                }
            }
        }

        private unsafe void method_6(long long_0, long long_1)
        {
            long_0 /= 0x400L;
            long_1 /= 0x400L;
            int k = (Convert.ToInt32(long_0) * 100) / Convert.ToInt32(long_1);
            this.int_1 = k - this.progressBarControl_0.Position;
            bool isInvoke = !this.progressBarControl_0.InvokeRequired;
            if (isInvoke)
            {
                ProcessDownLoad.UpdateProcCallbackEventHander method = new ProcessDownLoad.UpdateProcCallbackEventHander(this.method_6);
                base.Invoke(method, new object[] { long_0 * 0x400L, long_1 * 0x400L });
            }
            else
            {
                isInvoke = this.int_1 <= 0;
                if (isInvoke)
                {
                    this.progressBarControl_0.Increment(this.int_1);
                    this.labelControl_7.Text = long_0.ToString("#,###") + " KB / " + long_1.ToString("#,###") + " KB";
                    this.progressBarControl_0.Update();
                    this.labelControl_7.Update();
                }
            }
        }

        private unsafe void method_7(long long_0)
        {
            bool ischeck = base.InvokeRequired;
            if (!ischeck)
            {
                this.labelControl_9.Text = (long_0 / 0x400L) + " KB";
                long k = long_0 / 0x400L;
                this.labelControl_7.Text = "0 KB / " + (k).ToString("#,###") + " KB";
            }
            else
            {
                base.BeginInvoke(new ProcessDownLoad.SendTotalSizeEventHander(this.method_7), new object[] { long_0 });
            }
        }

        private void method_8()
        {
            this.icontainer_0 = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(XfmUpdateOnline));
            this.wizardControl_0 = new WizardControl();
            this.welcomeWizardPage_0 = new WelcomeWizardPage();
            this.labelControl_1 = new LabelControl();
            this.labelControl_2 = new LabelControl();
            this.labelControl_3 = new LabelControl();
            this.labelControl_0 = new LabelControl();
            this.completionWizardPage_0 = new CompletionWizardPage();
            this.labelControl_4 = new LabelControl();
            this.labelControl_5 = new LabelControl();
            this.labelControl_6 = new LabelControl();
            this.labelControl_7 = new LabelControl();
            this.labelControl_8 = new LabelControl();
            this.labelControl_9 = new LabelControl();
            this.progressBarControl_0 = new ProgressBarControl();
            this.defaultLookAndFeel_0 = new DefaultLookAndFeel(this.icontainer_0);
            this.wizardControl_0.BeginInit();
            this.wizardControl_0.SuspendLayout();
            this.welcomeWizardPage_0.SuspendLayout();
            this.completionWizardPage_0.SuspendLayout();
            this.progressBarControl_0.Properties.BeginInit();
            base.SuspendLayout();
            this.wizardControl_0.CancelText = "Huỷ bỏ";
            this.wizardControl_0.Controls.Add(this.welcomeWizardPage_0);
            this.wizardControl_0.Controls.Add(this.completionWizardPage_0);
            this.wizardControl_0.FinishText = "&Ho\x00e0n Tất";
            this.wizardControl_0.Name = "wcUpdate";
            this.wizardControl_0.NextText = "&Đồng \x00fd >";
            this.wizardControl_0.Pages.AddRange(new BaseWizardPage[] { this.welcomeWizardPage_0, this.completionWizardPage_0 });
            this.wizardControl_0.Text = "HRM HRM 2012 (Cập Nhật Trực Tuyến)";
            this.wizardControl_0.WizardStyle = WizardStyle.WizardAero;
            this.wizardControl_0.FinishClick += new CancelEventHandler(this.wizardControl_0_FinishClick);
            this.wizardControl_0.NextClick += new WizardCommandButtonClickEventHandler(this.wizardControl_0_NextClick);
            this.wizardControl_0.CancelClick += new CancelEventHandler(this.wizardControl_0_CancelClick);
            this.welcomeWizardPage_0.AllowNext = false;
            this.welcomeWizardPage_0.Controls.Add(this.labelControl_1);
            this.welcomeWizardPage_0.Controls.Add(this.labelControl_2);
            this.welcomeWizardPage_0.Controls.Add(this.labelControl_3);
            this.welcomeWizardPage_0.Controls.Add(this.labelControl_0);
            this.welcomeWizardPage_0.Name = "welcomePage";
            this.welcomeWizardPage_0.Size = new Size(0x1b6, 0x8e);
            this.welcomeWizardPage_0.Text = "T\x00ecm Bản Cập Nhật Mới";
            this.labelControl_1.Appearance.Font = new Font("Tahoma", 9.75f);
            this.labelControl_1.Appearance.Options.UseFont = true;
            this.labelControl_1.Location = new Point(3, 0x25);
            this.labelControl_1.Name = "lbStatus";
            this.labelControl_1.Size = new Size(0x70, 0x10);
            this.labelControl_1.TabIndex = 14;
            this.labelControl_1.Text = "... Chuẩn bị kết nối ";
            this.labelControl_2.Appearance.Font = new Font("Tahoma", 9.75f);
            this.labelControl_2.Appearance.Options.UseFont = true;
            this.labelControl_2.Location = new Point(0x81, 3);
            this.labelControl_2.Name = "lbVersion";
            this.labelControl_2.Size = new Size(0x24, 0x10);
            this.labelControl_2.TabIndex = 13;
            this.labelControl_2.Text = "?.?.?.?";
            this.labelControl_3.Appearance.Font = new Font("Tahoma", 9.75f);
            this.labelControl_3.Appearance.Options.UseFont = true;
            this.labelControl_3.Location = new Point(3, 3);
            this.labelControl_3.Name = "lbCurrentVersion";
            this.labelControl_3.Size = new Size(0x74, 0x10);
            this.labelControl_3.TabIndex = 12;
            this.labelControl_3.Text = "Phi\x00ean Bản Hiện Tại :";
            this.labelControl_0.Appearance.Font = new Font("Tahoma", 9.75f);
            this.labelControl_0.Appearance.Options.UseFont = true;
            this.labelControl_0.Location = new Point(3, 0x7b);
            this.labelControl_0.Name = "labelControl3";
            this.labelControl_0.Size = new Size(0x167, 0x10);
            this.labelControl_0.TabIndex = 11;
            this.labelControl_0.Text = "Nhấn n\x00fat < Đồng \x00fd > để bắt đầu tiến tr\x00ecnh cập nhật phần mềm";
            this.completionWizardPage_0.Controls.Add(this.labelControl_4);
            this.completionWizardPage_0.Controls.Add(this.labelControl_5);
            this.completionWizardPage_0.Controls.Add(this.labelControl_6);
            this.completionWizardPage_0.Controls.Add(this.labelControl_7);
            this.completionWizardPage_0.Controls.Add(this.labelControl_8);
            this.completionWizardPage_0.Controls.Add(this.labelControl_9);
            this.completionWizardPage_0.Controls.Add(this.progressBarControl_0);
            this.completionWizardPage_0.Name = "completePage";
            this.completionWizardPage_0.Size = new Size(0x1b6, 0x8e);
            this.completionWizardPage_0.Text = "Cập Nhật Phần Mềm";
            this.labelControl_4.Location = new Point(20, 0x7b);
            this.labelControl_4.Name = "lbFinalStatus";
            this.labelControl_4.Size = new Size(0, 13);
            this.labelControl_4.TabIndex = 13;
            this.labelControl_5.Appearance.Font = new Font("Tahoma", 9.75f);
            this.labelControl_5.Appearance.Options.UseFont = true;
            this.labelControl_5.Location = new Point(20, 0x60);
            this.labelControl_5.Name = "lbExtractStatus";
            this.labelControl_5.Size = new Size(0, 0x10);
            this.labelControl_5.TabIndex = 12;
            this.labelControl_6.Appearance.Font = new Font("Tahoma", 9.75f);
            this.labelControl_6.Appearance.Options.UseFont = true;
            this.labelControl_6.Location = new Point(20, 70);
            this.labelControl_6.Name = "lbProcesstext";
            this.labelControl_6.Size = new Size(0x3b, 0x10);
            this.labelControl_6.TabIndex = 11;
            this.labelControl_6.Text = "... Bắt đầu";
            this.labelControl_7.Appearance.Font = new Font("Tahoma", 9.75f);
            this.labelControl_7.Appearance.Options.UseFont = true;
            this.labelControl_7.Location = new Point(0x76, 6);
            this.labelControl_7.Name = "lbSizeStatus";
            this.labelControl_7.Size = new Size(0x13, 0x10);
            this.labelControl_7.TabIndex = 10;
            this.labelControl_7.Text = "0/0";
            this.labelControl_8.Appearance.Font = new Font("Tahoma", 9.75f);
            this.labelControl_8.Appearance.Options.UseFont = true;
            this.labelControl_8.Location = new Point(5, 6);
            this.labelControl_8.Name = "labelControl2";
            this.labelControl_8.Size = new Size(0x63, 0x10);
            this.labelControl_8.TabIndex = 9;
            this.labelControl_8.Text = "Dung Lượng Tải :";
            this.labelControl_9.Appearance.Font = new Font("Tahoma", 9.75f);
            this.labelControl_9.Appearance.Options.UseFont = true;
            this.labelControl_9.Location = new Point(0x18e, 6);
            this.labelControl_9.Name = "lbSize";
            this.labelControl_9.Size = new Size(0x19, 0x10);
            this.labelControl_9.TabIndex = 8;
            this.labelControl_9.Text = "0 KB";
            this.labelControl_9.Visible = false;
            this.progressBarControl_0.EditValue = "0";
            this.progressBarControl_0.Location = new Point(2, 0x1d);
            this.progressBarControl_0.Name = "progressBar";
            this.progressBarControl_0.Properties.ShowTitle = true;
            this.progressBarControl_0.Properties.Step = 0;
            this.progressBarControl_0.Size = new Size(0x1b3, 0x12);
            this.progressBarControl_0.TabIndex = 7;
            this.defaultLookAndFeel_0.LookAndFeel.SkinName = "Blue";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1f2, 0x130);
            base.Controls.Add(this.wizardControl_0);
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "XfmUpdateOnline";
            base.ShowIcon = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.wizardControl_0.EndInit();
            this.wizardControl_0.ResumeLayout(false);
            this.welcomeWizardPage_0.ResumeLayout(false);
            this.welcomeWizardPage_0.PerformLayout();
            this.completionWizardPage_0.ResumeLayout(false);
            this.completionWizardPage_0.PerformLayout();
            this.progressBarControl_0.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void wizardControl_0_CancelClick(object sender, CancelEventArgs e)
        {
            base.Close();
            this.processInitUpdate_0.Close();
            this.processDownLoad_0.Close();
            Application.ExitThread();
            Application.Exit();
        }

        private void wizardControl_0_FinishClick(object sender, CancelEventArgs e)
        {
            if (this.downloaderState_0 != DownloaderState.EndExtract)
            {
                XtraMessageBox.Show("Đang trong tiến tr\x00ecnh cập nhật", "Cảnh B\x00e1o");
            }
            else
            {
                base.Close();
            }
        }

        private void wizardControl_0_NextClick(object sender, WizardCommandButtonClickEventArgs e)
        {
            if (File.Exists(Application.StartupPath + @"\" + this.updateFile_0.ZipName + ".zip"))
            {
                File.Delete(Application.StartupPath + @"\" + this.updateFile_0.ZipName + ".zip");
            }
            this.processDownLoad_0.Start(this.updateFile_0);
            this.processDownLoad_0.SendTotalSize += new ProcessDownLoad.SendTotalSizeEventHander(this.method_7);
            this.processDownLoad_0.UpdateProcCallback += new ProcessDownLoad.UpdateProcCallbackEventHander(this.method_6);
            this.processDownLoad_0.DownLoadStatus += new ProcessDownLoad.DownLoadStatusEventHander(this.method_5);
            this.processDownLoad_0.ExtractFile += new ProcessDownLoad.ExtractFileEventHander(this.method_4);
        }

        public delegate void EnableButtonEventHander(bool isEn);
    }
}

